import Vue from 'vue';
import Vuex from 'vuex'
import axios from '../utils/http'

Vue.use(Vuex);

const MenuStore = {
    namespaced: true,
    state: () => ({
        menuList: []
    }),
    mutations: {
        MenuListMutation(state, list) {
            state.menuList = list
        }
    },
    actions: {
        MenuListAction(context) {
            axios.get("/api/menulist?istree=1").then(
                res => {
                    if (res.code === 403) {
                        localStorage.removeItem("login_data")
                        window.location.href = "/login"
                    } else {
                        if (res.code === 200) {
                            // console.log(res);
                            context.commit('MenuListMutation',res.list)
                        }
                    }
                }
            )
        }
    }
}

export default MenuStore
